package com.atguigu.spring.methodOverrides;

import com.atguigu.spring.methodOverrides.lookup.FruitPlate;
import com.atguigu.spring.methodOverrides.lookup.LookupConfig;
import com.atguigu.spring.methodOverrides.replace.OriginalDog;
import com.atguigu.spring.methodOverrides.replace.ReplaceConfig;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class OverridesMainTest2 {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(LookupConfig.class);

		BeanDefinition apple = context.getBeanDefinition("apple");
		System.out.println(apple);


		System.out.println("apple:" + context.getBean("fruitPlate1", FruitPlate.class).getFruit());
		System.out.println("apple:" + context.getBean("fruitPlate1", FruitPlate.class).getFruit());

		System.out.println("banana:" + context.getBean("fruitPlate2", FruitPlate.class).getFruit());
		System.out.println("banana:" + context.getBean("fruitPlate2", FruitPlate.class).getFruit());

		System.out.println(context.getBean("fruitPlate1"));
		System.out.println(context.getBean("fruitPlate2"));


		System.out.println("-------------------------------------");

		ClassPathXmlApplicationContext xmlApplicationContext = new ClassPathXmlApplicationContext("lookup.xml");


		System.out.println(xmlApplicationContext.getBean("fruitPlate1"));
		System.out.println(xmlApplicationContext.getBean("fruitPlate2"));


		System.out.println("-------------------------------------");

		ClassPathXmlApplicationContext xmlApplicationContext2 = new ClassPathXmlApplicationContext("replace.xml");
		OriginalDog originalDog = xmlApplicationContext2.getBean("originalDogReplaceMethod", OriginalDog.class);
		String helloWhat = originalDog.sayHello("参数是啥");
		System.out.println(helloWhat);

		System.out.println("--------------------------------------");


		AnnotationConfigApplicationContext replaceAnnoContext = new AnnotationConfigApplicationContext(ReplaceConfig.class);
		OriginalDog originalDog1 = replaceAnnoContext.getBean(OriginalDog.class);
		originalDog1.sayHello("参数是啥");

	}

}
